package wc

import (
	"fmt"
	"io/ioutil"
	"main/env"
	"main/protos"
	"net/http"
	"net/url"
)

func RunBookServer(input string) string {
	v := url.Values{}
	v.Set("input", input)

	resp, err := http.Get(fmt.Sprintf("http://%s/get?", env.BookServer) + v.Encode())
	if err != nil {
		return "图书服务暂时不好使了。" + err.Error()
	}
	defer resp.Body.Close()
	content, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		return "图书服务暂时不好使了。" + err.Error()
	}
	var j = protos.BaseMessage{}

	err = j.XXX_Unmarshal(content)
	if err != nil {
		return "图书服务暂时不好使了。" + err.Error()
	}
	return string(j.Data)
}
